JBoss Messaging Queue Failover Example

$Revision: 82920 $

Overview


This example demonstrates the transparent failover of a JMS consumer. A connection is made on one node of the cluster and two messages are sent. A consumer is created and one of the messages is consumed. The node the connection is connected to then fails and the connection fails over onto the second node. The second message is then consumed using the same consumer.

This example relies on having access to a running JBoss Messaging cluster with at least two nodes. The JBoss Messaging cluster must be installed and started according to the userguide.


For JBoss5, you should copy all as messaging-node0, configure mysql as a database, make it clustered, and copy it as messaging-node1. Start each instance as:

./run -c messaging-node0 -Djboss.service.binding.set=ports-01


and in another window

./run.sh -c messaging-node1 -Djboss.service.binding.set=ports-02 -Djboss.messaging.ServerPeerID=1

Running the example


1. Make sure that a JBoss Messaging cluster with at least two nodes is up and running.

2. Go to the example's home directory

cd ...\examples\queue-failover

3. Run the example:

ant


The output of a successful run should be similar to:


$ ant
Buildfile: build.xml

identify:
     [echo] ###########################################################################
     [echo] #                Running the QUEUE FAILOVER example                       #
     [echo] ###########################################################################
     [echo] The queue:      testDistributedQueue
     [echo] The client jar: ../../../output/lib/jboss-messaging-client.jar

sanity-check:

init:

compile:

jar:

deploy:

sleep:
     [echo] Sleeping for 5 seconds ...

run:
     [java] Distributed queue /queue/testDistributedQueue exists
     [java] The messages were successfully sent to the distributed queue
     [java] Received message: Hello1!
     [java] 11:12:22,359 ERROR @Timer-0 [SocketClientInvoker] Got marshalling exception, exiting
     [java] java.io.IOException: Connection reset by peer: socket write error
     [java]     at java.net.SocketOutputStream.socketWrite0(Native Method)
     [java]     at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
     [java]     at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
     [java]     at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
     [java]     at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
     [java]     at java.io.DataOutputStream.flush(DataOutputStream.java:106)
     [java]     at org.jboss.serial.io.JBossObjectOutputStream.flush(JBossObjectOutputStream.java:248)
     [java]     at org.jboss.jms.server.remoting.JMSWireFormat.serialize(JMSWireFormat.java:1035)
     [java]     at org.jboss.jms.server.remoting.JMSWireFormat.write(JMSWireFormat.java:413)
     [java]     at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.versionedWrite(MicroSocketClientInvoker.java:518)
     [java]     at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:340)
     [java]     at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:125)
     [java]     at org.jboss.remoting.ConnectionValidator.checkConnection(ConnectionValidator.java:184)
     [java]     at org.jboss.remoting.ConnectionValidator.run(ConnectionValidator.java:114)
     [java]     at java.util.TimerThread.mainLoop(Timer.java:512)
     [java]     at java.util.TimerThread.run(Timer.java:462)
     [java] 11:12:24,406 INFO  @Thread-3 [HAAspect] HAAspect.ClusteredClientConnectionFactoryDelegate[1] completed client-side failover
     [java] Received message: Hello2!
     [java] The example connected to JBoss Messaging version 1.4.1.GA (1.4)

     [java] #####################
     [java] ###    SUCCESS!   ###
     [java] #####################

undeploy:
   [delete] Deleting: C:\dev\jboss-5.0.0.GA\server\messaging-node0\deploy\application-server-killer.jar

BUILD SUCCESSFUL
Total time: 41 seconds